// pages/index/analysis.js
var util = require('../../utils/util');
const wxCharts = require('../../utils/wxcharts.js');

var radarChart = null;
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barimages: ['../../images/bnav4h.png', '../../images/bnav2n.png', '../../images/bnav3n.png'],
    "sex": 1,
    "jrnl_str": "很差",
    "weight": 96,
    "rrx_score": 1,
    "bmi": 28.7,
    "rrx_str": "优秀",
    "xfnl_score": 0.6,
    "bodyStr": "您的BMI属于:I度肥胖,腰臀比:0.7 正常.您的体脂率:23.3 偏高,需要降低皮脂厚度,并加强肌肉线条感",
    "jrnl_score": 0.01,
    "datuiwei": 35,
    "ydlStr": "很差",
    "ydlScore": 1.135,
    "lifeStr": "较差",
    "qianbiwei": 22,
    "height": 183,
    "tzl": 23.3,
    "lifeScore": 0.3,
    "age": 22,
    "ytb": 0.7,
    "xiaotuiwei": 23,
    "body_score": 0.5,
    "tunwei": 74,
    "xfnl_score_str": "尚可",
    "nickName":"",
    "jxxl":""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // util.sendRequest("WxGetUserInfo", "", res => {

    //   this.setData(res.result);
    // });
    this.showRadar();
  },
showRadar(){
  var windowWidth = 320;
  
  try {
    var res = wx.getSystemInfoSync();
    windowWidth = res.windowWidth;
  } catch (e) {
    console.error('getSystemInfoSync failed!');
  }
  // TODO有些字段没有 做的随机数
  util.sendRequest("WxGetRadar","",res=>{
    const result = res.result;
    this.setData(result);
    const data = [+result.body_score * 100, +result.lifeScore * 100, +result.ydlScore * 100, +result.xfnl_score * 100, +result.rrx_score * 100, +result.jrnl_score * 100];
  radarChart=new wxCharts({
    canvasId: 'radarCanvas',
    type: 'radar',
    categories: ['身体形态',  '生活习惯', '运动量', '心肺耐力', '柔韧性',"肌肉耐力"],
   legend:false,
    series: [{
      name: '整体分析',
      data,
      color:"#FF9900"
    }],
    width: windowWidth,
    height: 200,
    extra: {
      radar: {
        max: 100,
        labelColor: '#000000',
      
      }
    }
  })
  });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  toLx: function () {
    wx.redirectTo({
      url: '/pages/personal/perplan2',
    })
  },
  toMine: function () {
    wx.redirectTo({
      url: '/pages/personal/percenter',
    })
  },
})